package com.common.www.bean.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.boot.base.jpa.domain.entity.NumberIdentityEntity;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Entity
@DynamicUpdate(true)
@DynamicInsert(true)
@Getter
@Setter
@ToString()
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class TestDatabase extends NumberIdentityEntity {
    private static final long serialVersionUID = 3170440352426050769L;

    @Column(length = 256)
    private String testName;
    /**
     * 库存模拟测试
     */
    private Integer inventory;

    /**
     * 父节点类型
     */
    @JsonIgnoreProperties(value = {"parent", "children"})
    @ManyToOne()
    @JoinColumn(name = "parent")
    private TestDatabase parent;

    //二级分类
    @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "parent")
    private List<TestDatabase> children;
}
